﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DEMO_TEMP1
{
    public partial class Form3 : Form
    {
        DataSet data = new DataSet();
        DataTable MAW_List = new DataTable();
        string userid,MAWB = string.Empty;
        int index = 0;
        public Form3(string user ,DataSet ds, string mawb)
        {
            InitializeComponent();
            data = ds;
            userid = user;
            this.MAWB = mawb;
            if (data==null)
            {
                label2.Visible = true;
                label2.Text = "Data not found";
            }
            else
            {
                
                
               
                    MAW_List = CreateTableMAWB(data);
                    dataGrid1.DataSource = MAW_List;
                   // dataGrid1.DataSource = data;
                
               
            }
        }
        string mawb_no, fln,fld;
        public DataTable CreateTableMAWB(DataSet ds)
        {
            //WebPor.Service1 con = new WebPor.Service1();
            //con.Url = string.Format("http://192.168.1.220/WebAppPor01/Service1.asmx");
            if (data==null)
            {
                return null;
            }
            else
            {
                
                DataTable MAWB_list = new DataTable();
              //  MAWB_list.Columns.Add("No", typeof(int));
                MAWB_list.Columns.Add("MAWB", typeof(string));
                MAWB_list.Columns.Add("Flight no", typeof(string));
                MAWB_list.Columns.Add("Flight date", typeof(string));
                ////////////////////Getdata form dataset//////////////////////////
                //int row = con.GetcountMAWB(MAWB);
                for (int i = 0; i < data.Tables[0].Rows.Count; i++)
                {
                    mawb_no = data.Tables[0].Rows[i]["display_mawb"].ToString().Trim();
                    fln = data.Tables[0].Rows[i]["display_flight_number"].ToString().Trim();
                    fld = data.Tables[0].Rows[i]["display_flight_date"].ToString().Trim();
                    //string timef = ds.Tables[0].Rows[i]["flight_date"].ToString();
                    //DateTime dt = DateTime.Parse(timef);
                    //fld = String.Format("{0:ddMMMyy}", dt);
                    //mawb_no = ds.Tables[0].Rows[i]["mawb_no"].ToString().Trim();
                    ////mawb_no = data.Tables[0].Rows[0]["mawb_no"].ToString().Trim();
                    ////flt = "BA010/09";
                    //fln = ds.Tables[0].Rows[i]["carr"].ToString().Trim() + ds.Tables[0].Rows[i]["flight_no"].ToString().Trim();
                    /////////////////////////////////////////////////////////////////
                    MAWB_list.Rows.Add(mawb_no, fln,fld);
                }
                //////////////set size Table////////////////////////////////////
                if (data.Tables[0].Rows.Count!=0)
                {
                    MAWB = data.Tables[0].Rows[0]["display_mawb"].ToString().Trim(); 
                }
                
                ////////////////////////////////////////////////////////////////
                return MAWB_list;
            }
            
        }

        private void menuItem1_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2(userid);
            f2.Show();
            this.Close();
        }

        private void menuItem2_Click(object sender, EventArgs e)
        {
            Form4 f4 = new Form4(userid,data, index);
            f4.Show();
        }
        private void dataGrid1_Click(object sender, EventArgs e)
        {
            dataGrid1.Select(dataGrid1.CurrentRowIndex);
            string m = string.Empty;
            m = dataGrid1.CurrentRowIndex.ToString();
            MessageBox.Show(m);
          int  m2 = int.Parse(m);
          index = m2;
          MAWB =   selectMAWB(m2);
            // MessageBox.Show(m);

        }
        private string selectMAWB(int m)
        {
            string mawb  = data.Tables[0].Rows[m]["display_mawb"].ToString().Trim();
            //index = m;
            return mawb;
        }

        private void dataGrid1_Click_1(object sender, EventArgs e)
        {
            string m = string.Empty;
            m = dataGrid1.CurrentRowIndex.ToString();
            //MessageBox.Show(m);
            int m2 = int.Parse(m);
            index = m2;
          MAWB=  selectMAWB(m2);
        }

        private void dataGrid1_DoubleClick(object sender, EventArgs e)
        {
            dataGrid1.UnSelect(dataGrid1.CurrentRowIndex);
        }

      
    }
}